// TOWN SCRIPT
//    Town 1: Fort Kingdom
// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k;
int level, modifier;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.

//prep party (copied/pasted from EP to save time)

force_view_center(36,44);
force_instant_terrain_redraw();
set_character_pose(1000,14);
force_instant_terrain_redraw();

pause(5);

force_instant_terrain_redraw();
message_dialog("You wake up to the sounds of combat. You struggle to remember where you are for a moment - too many nights on the road always has that effect. Slowly, things come back to you.","You're lying in a bed in Fort Kingdom. It's morning, and you've no doubt that the goblin menace that has been invading the Fort has crept closer to the Fort during the night.");
message_dialog("Your equipment is in the chest in your room - you're going to need everything available to fight off the invaders...","");

set_character_pose(1000,0);
relocate_character(0,36,44);
force_instant_terrain_redraw();

set_name(15,"Kelsa.");


break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.

if(item_type_in_slot(0,1) != -1) {
	if(get_flag(1,0) == 0) {
		alter_stat(0,4,3);
		set_flag(1,0,1);
	} 
}

if(item_type_in_slot(0,1) == -1) {
	if(get_flag(1,0) == 1) {
		alter_stat(0,4,-3);
		set_flag(1,0,0);
	} 
}


break;

beginstate 10;
	if(get_flag(1,1) == 0) {
		message_dialog("The barracks are empty - the soldiers who were stationed here with you must have left already.","Listening carefully, you can hear the sounds of battle in the background...");
		set_flag(1,1,1);
	}
break;

beginstate 11;
	if(get_flag(1,2) == 0) {
		message_dialog("In the courtyard ahead, you can make out a number of corpses littering the ground. Their blood lies in sickly pools on the ground. They look as though they died recently.","What really catches your eye, though, are the goblins hiding behind a barricade to the west. They spot you, and raise their slings...");
		set_flag(1,2,1);
	}
break;

beginstate 12;
	if(get_flag(1,3) == 0) {
		message_dialog("Up ahead you spot several goblins looting a corpse. One of them pulls at the dead body's leather armour with grubby paws, whilst another tries to prise off a wedding ring with it's teeth.","Suddenly, the turn around and spot you. Growling, they advance...");
		set_flag(1,3,1);
	}
break;

beginstate 13;
	if(get_flag(1,4) == 0) {
		message_dialog("As you approach this small clearing, you spot the two goblins that were flinging rocks at you earlier run past you, probably to take up another position.","Looking around, you can see more corpses - your kinsmen cut down by the goblins... It's beginning to seem like you're the only person alive in this part of the city...");
		erase_char(6);
		erase_char(7);
		set_flag(1,4,1);
	}
break;
		
beginstate 14;
	if(get_flag(1,5) == 0) {
		message_dialog("As you make your way further into the clearing, you spot another set pair of goblins hiding behind another barricade. They spot you, and grin.","You suspect that they're waiting for you to get closer before pelting you with stones...");
		set_flag(1,5,1);
	}
break;

beginstate 15;
	if(get_flag(1,6) == 0) {
		message_dialog("As you step out into this courtyard, you spot somebody alive in the midst of this over-run town. Bizarely, she is just staring into space, apparently unaware of where she is...","");
		set_flag(1,6,1);
	}
break;

beginstate 16;
	message_dialog("The girl doesn't move when you approach, and she stays silent when you speak to her.","There doesn't seem to be anything you can do to get her attention..,");
break;

beginstate 17;
	if(get_flag(1,7) == 0) {
		message_dialog("As you make your way into the large courtyard in front of Spektor Manor, the two goblins from earlier move into the barricade to the east, and look around for people to attack...","");
		activate_hidden_group(1);
		set_flag(1,7,1);
	}
break;

beginstate 18; 	
	if(get_flag(1,8) == 0) {
		message_dialog("This little quad in the south-west corner of Fort Kingdom is blissfully free of the goblins that have spread through the rest of the Fort. There aren't even any bodies, which makes a nice change of pace.","However, the guardpost is ahead, and it's likely that there will be invaders there.");
		set_flag(1,8,1);
		erase_char(11);
		erase_char(12);
	}
break;

beginstate 19;
	reset_dialog();
	add_dialog_str(0,"You approach the the exit of this section of Fort Kingdom. You should porbably go and find out if the goblins have managed to get into the rest of the Fort. Do you?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		message_dialog("You run off, eager to join the fight","");
		move_to_new_town(2,35,44);
		force_instant_terrain_redraw();
	} else {
		block_entry(1);
	}
break;